using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ResourceLoadPanel : BasePanel
{

    public TMPro.TextMeshProUGUI text;
    public Image background;
    int porcess,targetPorcess;

    public RectTransform fillImage;
    public RectTransform bgImage;

    public override void Open(Vector3 pos, Vector3 scale)
    {
        base.Open(pos, scale);
        porcess = 0;
        RefreshUI();

    }


    public void SetPorcess(int p)
    {
        targetPorcess = p;
        // text.text = "loading..." + p.ToString() + "%";
        // fillImage.offsetMax = new Vector2((p / 100f - 1) * bgImage.sizeDelta.x, fillImage.offsetMax.y);
    }

    void Update()
    {
        if (targetPorcess > porcess)
        {
            porcess ++;
            RefreshUI();
        }
        else if (porcess >= 100)
        {
            porcess++;
            if (porcess>160)
            {
                Close();
            }
        }
    }

    void RefreshUI()
    {
        text.text = "loading..." + porcess.ToString() + "%";
        fillImage.offsetMax = new Vector2((porcess / 100f - 1) * bgImage.sizeDelta.x, fillImage.offsetMax.y);
    }

}
